import Vue from 'vue'
const Bus = new Vue()

export default Bus

const downLoadFileByBlob = (blob, title, postfix = '.xls') => {
  const link = document.createElement('a')
  link.href = window.URL.createObjectURL(blob)
  link.download = title + postfix
  link.click()
  window.URL.revokeObjectURL(link.href)
}

const ifImportSuccess = (column, templateData, importData) => { 
  const notAllowEdit = column.filter(item => {
    return item.edit === false && item.dataIndex !== 'budgetType'
  })

  for(let i = 0; i < notAllowEdit.length; i++) {

    const key = notAllowEdit[i].dataIndex
    const value = templateData[key]

    for(let j = 0; j < importData.length; j++) {
      if(value != importData[j][key]) {
        return false
      }
    }
    
  }
  return true
}

export {
  downLoadFileByBlob,
  ifImportSuccess
}

